<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
"Mathematician clock" by Stephane Tsacas stephane.tsacas+eleeno@gmail.com
-->
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
   <title>Mathematician time (serie)</title>
<script type="text/javascript"><!--
// Set to something for debugging.
var debug = 0;

// Wrapper to new Date() so you can set the time manually when debugging.
function currentTime()
{
  var timeNow;

  if (debug)
    {
      timeNow = new Date(2009, 4, 1, 11, 33, 12); // Set the time as you want (3 last args).
    }
  else
    {
      timeNow = new Date();
    }
  return timeNow;
}

function cacheObjects()
{
  display = document.getElementById("clockDisplay");
}


var inited = 0;
// Main function, does it all. Called every second.
function blinkSomething()
{
  var timeNow = currentTime();
  var hours = timeNow.getHours();
  var minutes = timeNow.getMinutes();
  var seconds = timeNow.getSeconds();
  var timeString = '';

  display.innerHTML = '';

  timeString = String(hours < 10 ? '0' + hours : hours) 
    + String(minutes < 10 ? '0' + minutes : minutes)
    + String(seconds < 10 ? '0' + seconds : seconds)
    + 'X';

  var count = 1;
  for (var pos = 0; timeString[pos] != 'X'; pos++)
    {
      if (timeString[pos] == timeString[pos + 1])
	{
	  count++;
	  continue;
	}
      display.innerHTML += count + timeString[pos];
      count = 1;
    }
  //    decode(display.innerHTML); // For debug ;-)
}

function decode(o)
{
  document.getElementById("debug_div").innerHTML = '';

  for (var pos = 0; pos < o.length; pos += 2)
    {
      var n = o.charAt(pos);
      var c = o.charAt(pos + 1);
      for (var i = 0; i < n; i++) document.getElementById("debug_div").innerHTML += c;
    }
}
//-->
</script>
  </head>

<body onload="cacheObjects(); setInterval('blinkSomething()', 1000)" >
  <span id="clockDisplay" style='font:14pt "Courier New" "Courier" "Monaco"'></span>
  <div id='debug_div'></div>
</body>
</html>
